package com.alibaba.citrus.ots.price.ability.functions.factory.activity.process;

import com.alibaba.citrus.common.Result;
import com.alibaba.citrus.ots.price.ability.functions.entity.activity.ActivityTermEntity;
import com.alibaba.citrus.ots.price.ability.functions.entity.activity.ActivityTitleEntity;
import com.alibaba.citrus.ots.price.repository.ActivityQueryRepository;
import com.epoch.app.otspricecenter.dto.request.ActivityInfoRequest;
import com.epoch.app.otspricecenter.dto.request.ActivityItemInfo;
import com.epoch.app.otspricecenter.dto.request.ParticipateActivityInfoRequest;
import com.epoch.app.otspricecenter.dto.request.ParticipateActivityTermRequest;
import com.epoch.app.otspricecenter.dto.response.ActivityTermResponse;
import com.epoch.app.otspricecenter.model.enums.ActivityTypeEnum;
import com.epoch.app.otspricecenter.sdo.ActivityTermSDO;
import com.google.common.collect.Lists;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.Set;

/**
 * @author: qiaojiange
 * @create: 2021/11/18
 * @Description 补货活动类型
 */
@Component
public class ReplenishmentProcessor extends ActivityProcess {

    @Resource
    private ActivityQueryRepository queryRepository;

    @Override
    public List<ActivityTermEntity> addInfo(ActivityTitleEntity titleEntity, String itemId) {
        Set<ActivityTermSDO> activityTermSDOS = queryRepository.queryTermSDOList(titleEntity.obtainActivityId());
        List<ActivityTermEntity> activityTermEntities = Lists.newArrayList();

        activityTermSDOS.forEach(sdo -> {
            ActivityTermEntity activityTermEntity = ActivityTermEntity.of(sdo);
            activityTermEntities.add(activityTermEntity);
        });
        return activityTermEntities;
    }

    @Override
    public String getActivityTypeDesc() {
        return ActivityTypeEnum.REPLENISHMENT.getValue();
    }

    @Override
    public List<ActivityItemInfo> processGift(ActivityTermEntity activityTermEntity, ActivityInfoRequest request) {
        //补货类型不用处理赠品
        return null;
    }

    @Override
    public String processSpecialOfferPrice(ActivityTermEntity activityTermEntity, ActivityInfoRequest request) {
        //补货类型不用处理特价
        return null;
    }

    @Override
    public Long calculatePreOccupyFee(ActivityTermEntity activityTermEntity, ParticipateActivityTermRequest termRequest) {
        ActivityItemInfo item = termRequest.getItem();
        return item.getItemPrice() * item.getItemQuantity();
    }

    @Override
    public Integer calculateOccupyQuantity(ActivityTermEntity termEntity, ParticipateActivityTermRequest termRequest) {
        return 0;
    }

    @Override
    public Boolean filterTermOfCreate(ActivityTermEntity termEntity, String itemId) {
        return true;
    }

    @Override
    public Result<Boolean> checkParticipateActivityData(ParticipateActivityInfoRequest request, ActivityTermResponse response) {
        return Result.success(Boolean.TRUE);
    }

    @Override
    public Boolean checkPreOccupyQuantity(ActivityTermEntity termEntity, ParticipateActivityTermRequest termRequest, Integer preOccupyQuantity) {
        return true;
    }

    @Override
    public Boolean checkPreOccupyFee(ActivityTermEntity termEntity, Long thisPreOccupyFee) {
        return true;
    }
}
